package com.example.netty_pipline.config;

import com.example.netty_pipline.pipeline.ChannelPipeline;
import com.example.netty_pipline.pipeline.DefaultChannelPipeline;
import com.example.netty_pipline.pipeline.handler.BusinessHandler;
import com.example.netty_pipline.pipeline.handler.LoggingHandler;
import com.example.netty_pipline.pipeline.handler.StringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Pipeline配置类 - 配置处理器管道
 */
@Configuration
public class PipelineConfig {
    
    @Bean
    public ChannelPipeline messagePipeline() {
        ChannelPipeline pipeline = new DefaultChannelPipeline("messagePipeline");
        
        // 添加处理器到管道
        pipeline.addFirst("loggingInbound", new LoggingHandler("Inbound"))
               .addAfter("loggingInbound", "decoder", new StringDecoder())
               .addAfter("decoder", "business", new BusinessHandler())
               .addLast("loggingOutbound", new LoggingHandler("Outbound"));
        
        return pipeline;
    }
}